package primary.linkedList;

import java.util.List;

/**
 * @Author Elephas
 * @Date 2022/1/8
 **/
public class ReverseList {
    /*
        思路添加一个虚的头节点，然后用头插法得到结果
     */
    public ListNode reverseList(ListNode head){
        ListNode fakeHead = new ListNode(0,null);
        ListNode cur = head,temp;
        while(cur != null){
            temp = cur;
            cur = cur.next;
            temp.next = fakeHead.next;
            fakeHead.next = temp;
        }
        return fakeHead.next;
    }
}
